package xiaohong.data.tree.binary;

public class TreeDemo {

    public static void main(String[] args) {
        //创建一棵树
        BinaryTree binaryTree = new BinaryTree();
        //创建一个根节点
        TreeNode root = new TreeNode(1, "小宏");
        //把根节点赋给树
        binaryTree.setRoot(root);
        //创建左,右节点
        TreeNode rootLeft = new TreeNode(2, "最后");
        TreeNode rootRight = new TreeNode(3, "拦路雨");
        //把新建的节点设置为根节点的子节点
        root.setLeftNode(rootLeft);
        root.setRightNode(rootRight);
        //为第二层的左节点创建两个子节点
        TreeNode rootLeft1 = new TreeNode(4, "钢铁侠");
        TreeNode rootRight1 = new TreeNode(5, "美国队长");
        rootLeft.setLeftNode(rootLeft1);
        rootLeft.setRightNode(rootRight1);
        TreeNode rootLeft2 = new TreeNode(6, "怎么始终牵挂");
        TreeNode rootRight2 = new TreeNode(7, "黑寡妇");
        //为第二层的右节点创建两个子节点
        rootRight.setLeftNode(rootLeft2);
        rootRight.setRightNode(rootRight2);
        // 第三层
        rootLeft1.setLeftNode(new TreeNode(8, "灭霸"));
        rootLeft1.setRightNode(new TreeNode(9, "孙悟空"));
        rootRight1.setLeftNode(new TreeNode(10, "三太子"));
        rootRight1.setRightNode(new TreeNode(11, "东海龙王"));
        rootLeft2.setLeftNode(new TreeNode(12, "张三"));
        rootLeft2.setRightNode(new TreeNode(13, "李四"));
        rootRight2.setLeftNode(new TreeNode(14, "王五"));
        rootRight2.setRightNode(new TreeNode(15, "赵六"));
        // 前序遍历  1 2 4 8 9 5 10 11 3 6 12 13 7 14 15
//        binaryTree.frontShow();
        // 中序遍历  8 4 9 2 10 5 11 1 12 6 13 3 14 7 15
//        binaryTree.middleShow();
        // 后序遍历  8 9 4 10 11 5 2 12 13 6 14 15 7 3 1
//        binaryTree.afterShow();
        TreeNode treeNode = binaryTree.frontSearch(10);
        System.out.println("treeNode = " + treeNode);

        TreeNode treeNode1 = binaryTree.middleSearch(5);
        System.out.println("treeNode1 = " + treeNode1);

        binaryTree.delete(2);

        TreeNode treeNode2 = binaryTree.afterSearch(5);
        System.out.println("treeNode2 = " + treeNode2);



    }


}
